package com.xuelang.pipeline.artifact.entry.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.MemberService;
import com.xuelang.pipeline.artifact.app.harborv2.request.CreateMemberRequest;
import com.xuelang.pipeline.artifact.app.harborv2.request.ListMemberQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.SearchUserResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * HarborV2 项目成员原生接口web服务
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;
    /**
     * 得到项目成员列表
     *
     * @param projectNameOrId
     * @param query
     * @return
     */
    @GetMapping(value = "/projects/{project_name_or_id}/members", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> listProjectMember(@PathVariable("project_name_or_id") String projectNameOrId, @ModelAttribute ListMemberQuery query) {
        return memberService.listProjectMember(projectNameOrId, query);
    }

    /**
     * 创建项目成员
     *
     * @param projectNameOrId
     * @return
     */
    @PostMapping(value = "/projects/{project_name_or_id}/members", produces = "application/json;charset=utf-8")
    ApiResponseXO<SearchUserResponse> createProjectMember(@PathVariable("project_name_or_id") String projectNameOrId, @RequestBody @Valid CreateMemberRequest request) {
        return memberService.createProjectMember(projectNameOrId, request);
    }

    /**
     * 删除项目成员
     *
     * @param projectNameOrId
     * @param memberId
     * @return
     */
    @DeleteMapping(value = "/projects/{project_name_or_id}/members/{mid}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteProjectMember(@PathVariable("project_name_or_id") String projectNameOrId, @PathVariable("mid") String memberId) {
        return memberService.deleteProjectMember(projectNameOrId, memberId);
    }



}
